<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 1.let基本语法
        // let a;
        // let b = 10;
        // console.log(a,b); //undefined 10

        // 2.特点
        // 不存在变量提升  与  暂时性死区
        // 使用let声明的变量，在当前作用域下声明之前都是暂时性死区，不能使用这个变量
        // console.log(a); //ReferenceError: Cannot access 'a' before initialization(初始化)
        let a = 10;  //在21行之前（变量声明之前）都称之为 暂时性死区
        console.log(a);

        function test() {
            // console.log(b); //ReferenceError: Cannot access 'b' before initialization
            let b = 20;
            console.log(b);
        }

        test();



        // 不能重复声明
        let c = 20;
        // let c = 30;  //SyntaxError: Identifier 'c' has already been declared  语法错误：变量c是已经声明过

        let d;
        // let d; //SyntaxError: Identifier 'd' has already been declared
        d = 100;
        console.log(d);



        // 块级作用域
        // 使用let声明的变量存在块级作用域(就是{},大括号中可以写任意代码段)
        // function,for,if,while,switch(对象除外)
        // 依然符合作用域链
        {
            let e = 100;
        }

        {
            let e = 200;
        }

        let f = "测试";

        {
            console.log(f);
            let g = 200;
            // let g = 300; //SyntaxError: Identifier 'g' has already been declared
            {
                let g = 666;
                console.log(g);
                {
                    // console.log(x);//ReferenceError: Cannot access 'x' before initialization
                    let x = 22;
                }
            }
        }


    </script>
</body>

</html>